<template>
  <div class="invitation">
    <van-nav-bar title="推荐公众号" left-arrow @click-left="$router.history.go(-1)">
      <span slot='left' class="topleftIcon"><img src='../../../public/images/qt_75.png'/></span>
    </van-nav-bar>
    <div class="myInvitation">推荐公众号</div>
    <div class="contentNav">
      <van-list
        v-model="loading"
        :finished="finished"
        @load="onLoad"
        finished-text="没有更多了"
        :immediate-check="false"
        :offset='50'>
          <div class="tie flex flex-wrap">
            <div v-for="(item,index) in order" :key="index" class="item-box">
              <img class="head" :src="item.userPhoto" alt @click.stop='$router.push({path:"otherUser",query:{userId:item.userId}})'/>
              <p class="hide_other">{{item.userName ? item.userName : '暂未设置'}}</p>
              <img @click.stop='gz(item.userId,item.isFollow)' src="../../../public/images/qt_50.png" v-if='item.isFollow=="-1"' class="btn"  />
              <img @click.stop='gz(item.userId,item.isFollow)' src="../../../public/images/qt_53.png" v-else class="btn" />
            </div>
          </div>
        </van-list>
    </div>
  </div>
</template>

<script>
import storage from '@/common/store'
export default {
  data() {
    return {
      page:1,
      size:10,
      order:{},
      finished:false,
      loading:false,
    };
  },
  created(){
    this.getMessage();
  },
  methods:{
    getMessage(){
      this.$get(this.$api.blog.accounts,{size:this.size,page:this.page}).then(data=>{
        data.data.curPageData.forEach((item,index,array)=>{
          if(!item.userPhoto) array[index].userPhoto=require('../../../public/images/avtor.png');
        });
        this.order=data.data.curPageData;
        if(Number(this.page)*this.size>=data.data.totalNum) this.finished  = true;
        this.page=2;
      });
    },
    gz(userId,follow){
      let that=this;
      this.vueGz(userId,follow,function(){
        that.getMessage();
      })
    },
    onLoad() {
      setTimeout(() => {
        this.$get(this.$api.blog.accounts,{size:this.size,page:this.page}).then(data=>{
          if((Number(this.page)-1)*this.size<data.data.totalNum){
            data.data.curPageData.forEach((item,index,array)=>{
              if(!item.userPhoto) array[index].userPhoto=require('../../../public/images/avtor.png');
            })
            for (let i = 0; i < data.data.curPageData.length; i++) {
              this.order.push(data.data.curPageData[i]);
            };
            this.loading = false;
          }else{
            this.loading = false;
            this.finished  = true;
          }
          this.page++;
        })
      }, 500);
    },
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.myInvitation {
  height: 1rem;
  background-color: #fff;
  font: 0.3rem/1rem "微软雅黑";
  color: #999999;
  margin-left: 0.3rem;
}
.tie {
  padding: 0.2rem 0.2rem 0 0.2rem;
  border-top: 0.3rem solid #f5f5f5;
}

.tie .item-box {
  width: 1.26rem;
  text-align: center;
  margin: 0 0.25rem 0.8rem 0.25rem;
}
.tie .item-box .head {
  width: 1.2rem;
  height: 1.2rem;
  display: block;
  border-radius: 50%;
  margin: 0 auto;
}
.tie .item-box p {
  width: 1.26rem;
  height: 0.28rem;
  font-size: 0.28rem;
  line-height: 0.28rem;
  padding: 0.17rem 0 0.3rem 0;
}
.tie .item-box .btn {
  width: 1.26rem;
  display: block;
}


.contentNav{height: calc(100vh - 1rem - 46px);overflow-y: scroll;}
</style>
